package ControlLayer;

import java.util.ArrayList;

import DBLayer.*;
import ModelLayer.*;

public class Ctr {

	public Ctr()
	{
		
	}
	/* START OF SUPPLIER CTR*/
	public ArrayList<Supplier> findAllSupplier()
    {
      DBSupplier dbEmp = new DBSupplier();
      ArrayList<Supplier> allEmp = new ArrayList<Supplier>();
      allEmp = dbEmp.miscWhere();
      return allEmp;
    }
	public Supplier findBySuID(int suID)
    {
        DBSupplier dbEmp = new DBSupplier();
        return dbEmp.findSupplier(suID);
    }
	public void updateSupplier(int suID,String fname, String lname, String ssn, String salary, int superssn)
    {
        DBSupplier dbEmp = new DBSupplier();
        Supplier emp = new Supplier();
        emp.setSuID(suID);
        emp.setName(fname);
        emp.setAddress(lname);
        emp.setCountry(ssn);
        emp.setE_mail(salary);
        emp.setPhone(superssn);
        dbEmp.updateSupplier(emp);
        
        
    }
	public void insertNewSupplier(String fname, String lname, String ssn, String salary, int superssn)
    {    

         try{
          DbConnection.startTransaction();
          DBSupplier dbEmp = new DBSupplier();
          dbEmp.createSupplier(fname,lname,ssn,salary,superssn);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	public void deleteSupplier(int suID)
	{ DBSupplier db = new DBSupplier();
	   db.deleteSupplier(suID);
		}
	/* END OF SUPPLIER CTR*/
	
	/* START OF Gun CTR*/
	public ArrayList<Gun> findAllGun()
    {
      DBGun dbEmp = new DBGun();
      ArrayList<Gun> allEmp = new ArrayList<Gun>();
      allEmp = dbEmp.miscWhere();
      return allEmp;
    }
	public Gun findBygID(int gID)
    {
        DBGun dbEmp = new DBGun();
        return dbEmp.findGun(gID);
    }
	public void updateGun(int gID,String fname, String lname)
    {
        DBGun dbEmp = new DBGun();
        Gun emp = new Gun();
        emp.setgID(gID);
        emp.setFabric(fname);
        emp.setCaliber(lname);
        dbEmp.updateGun(emp);
        
        
    }
	public void insertNewGun(String fname, String lname)
    {    

         try{
          DbConnection.startTransaction();
          DBGun dbEmp = new DBGun();
          dbEmp.createGun(fname,lname);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	public void deleteGun(int gID)
	{ DBGun db = new DBGun();
	   db.deleteGun(gID);
		}
	/* END OF Gun CTR*/
	
	/* START OF Clothing CTR*/
	public ArrayList<Clothing> findAllClothing()
    {
      DBClothing dbEmp = new DBClothing();
      ArrayList<Clothing> allEmp = new ArrayList<Clothing>();
      allEmp = dbEmp.miscWhere();
      return allEmp;
    }
	public Clothing findByclID(int clID)
    {
        DBClothing dbEmp = new DBClothing();
        return dbEmp.findClothing(clID);
    }
	public void updateClothing(int clID,String fname, String lname)
    {
        DBClothing dbEmp = new DBClothing();
        Clothing emp = new Clothing();
        emp.setClID(clID);
        emp.setColor(fname);
        emp.setSize(lname);
        dbEmp.updateClothing(emp);
        
        
    }
	public void insertNewClothing(String fname, String lname)
    {    

         try{
          DbConnection.startTransaction();
          DBClothing dbEmp = new DBClothing();
          dbEmp.createClothing(fname,lname);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	public void deleteClothing(int clID)
	{ DBClothing db = new DBClothing();
	   db.deleteClothing(clID);
		}
	/* END OF Clothing CTR*/
	
	/* START OF Product CTR*/
	public ArrayList<Product> findAllProduct()
    {
      DBProduct dbEmp = new DBProduct();
      ArrayList<Product> allEmp = new ArrayList<Product>();
      allEmp = dbEmp.miscWhere();
      return allEmp;
    }
	public Product findBypID(int pID)
    {
        DBProduct dbEmp = new DBProduct();
        return dbEmp.findProduct(pID);
    }
	public void updateProduct(int pID,String name,String price,String ocountry,int stock ,int suID,int clID,int eqID,int gID,int lID,boolean isLoan)
    {
        DBProduct dbEmp = new DBProduct();
        Product emp = new Product();
        emp.setpID(pID);
        emp.setName(name);
        emp.setPrice(price);
        emp.setOcountry(ocountry);
        emp.setStock(stock);
        emp.setSuID(suID);
        emp.setClID(clID);
        emp.setEqID(eqID);
        emp.setgID(gID);
        if(isLoan)
        {
        emp.setlID(lID);}
        else
        {emp.setlID(0);}
        dbEmp.updateProduct(emp);
        
        
    }
	public void insertNewProduct(String name,String price,String ocountry,int stock ,int suID,int clID,int eqID,int gID,int lID,boolean isLoan)
    {    

         try{
          DbConnection.startTransaction();
          DBProduct dbEmp = new DBProduct();
          dbEmp.createProduct(name,price, ocountry, stock , suID,clID, eqID, gID, lID, isLoan);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	public void deleteProduct(int pID)
	{ DBProduct db = new DBProduct();
	   db.deleteProduct(pID);
		}
	/* END OF Product CTR*/
	
	/* START OF Invoice CTR*/
	public ArrayList<Invoice> findAllInvoice()
    {
      DBInvoice dbEmp = new DBInvoice();
      ArrayList<Invoice> allEmp = new ArrayList<Invoice>();
      allEmp = dbEmp.miscWhere();
      return allEmp;
    }
	public Invoice findByiID(int iID)
    {
        DBInvoice dbEmp = new DBInvoice();
        return dbEmp.findInvoice(iID);
    }
	/*public void updateInvoice(String fname, String lname, String ssn, String salary, int superssn)
    {
        DBInvoice dbEmp = new DBInvoice();
        Invoice emp = new Invoice();
        emp.setName(fname);
        emp.setAddress(lname);
        
        dbEmp.updateInvoice(emp);
        
        
    }*/
	public void insertNewInvoice(String payment_date,String amount)
    {    

         try{
          DbConnection.startTransaction();
          DBInvoice dbEmp = new DBInvoice();
          dbEmp.createInvoice(payment_date,amount);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	public void deleteInvoice(int iID)
	{ DBInvoice db = new DBInvoice();
	   db.deleteInvoice(iID);
		}
	/* END OF Invoice CTR*/
	
	/* START OF Sale CTR*/
	public ArrayList<Sale> findAllSale()
    {
      DBSale dbEmp = new DBSale();
      ArrayList<Sale> allEmp = new ArrayList<Sale>();
      allEmp = dbEmp.miscWhere();
      return allEmp;
    }
	public Sale findBysID(int sID)
    {
        DBSale dbEmp = new DBSale();
        return dbEmp.findSale(sID);
    }
	public void updateSale(int sID,String date,int quantity,String deliveryS,String deliveryD,int cID,int pID,int iID)
    {
        DBSale dbEmp = new DBSale();
        Sale emp = new Sale();
        emp.setsID(sID);
        emp.setDate(date);
        emp.setQuantity(quantity);
        emp.setD_status(deliveryS);
        emp.setD_date(deliveryD);
        emp.setcID(cID);
        emp.setpID(pID);
        emp.setiID(iID);
        dbEmp.updateSale(emp);

        
    }
	public void insertNewSale(String date,int quantity,String deliveryS,String deliveryD,int cID,int pID,int iID)
    {    

         try{
          DbConnection.startTransaction();
          DBSale dbEmp = new DBSale();
          dbEmp.createSale(date, quantity, deliveryS, deliveryD, cID, pID, iID);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	public void deleteSale(int sID)
	{ DBSale db = new DBSale();
	   db.deleteSale(sID);
		}
	/* END OF Sale CTR*/
	/* START OF Loan CTR*/
	public ArrayList<Loan> findAllLoan()
    {
      DBLoan dbEmp = new DBLoan();
      ArrayList<Loan> allEmp = new ArrayList<Loan>();
      allEmp = dbEmp.miscWhere();
      return allEmp;
    }
	public Loan findBylID(int lID)
    {
        DBLoan dbEmp = new DBLoan();
        return dbEmp.findLoan(lID);
    }
	public void updateLoan(int lID,int amount,String l_status,String l_date,int l_duration,int cID)
    {
        DBLoan dbEmp = new DBLoan();
        Loan emp = new Loan();
        emp.setlID(lID);
        emp.setAmount(amount);
        emp.setL_status(l_status);
        emp.setL_date(l_date);
        emp.setL_duration(l_duration);
        emp.setcID(cID);
        dbEmp.updateLoan(emp);
        
        
    }
	public void insertNewLoan(int amount,String l_status,String l_date,int l_duration,int cID)
    {    

         try{
          DbConnection.startTransaction();
          DBLoan dbEmp = new DBLoan();
          dbEmp.createLoan(amount,l_status,l_date,l_duration,cID);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	public void deleteLoan(int lID)
	{ DBLoan db = new DBLoan();
	   db.deleteLoan(lID);
		}
	/* END OF Loan CTR*/
	
	/* START OF Customer CTR*/
	public ArrayList<Customer> findAllCustomer()
    {
      DBCustomer dbEmp = new DBCustomer();
      ArrayList<Customer> allEmp = new ArrayList<Customer>();
      allEmp = dbEmp.miscWhere();
      return allEmp;
    }
	public Customer findBycID(int cID)
    {
        DBCustomer dbEmp = new DBCustomer();
        return dbEmp.findCustomer(cID);
    }
	public void updateCustomer(int cID,String fname, String lname,String address,String city,int zip,String phone,int ssn)
    {
        DBCustomer dbEmp = new DBCustomer();
        Customer emp = new Customer();
        emp.setcID(cID);
        emp.setFname(fname);
        emp.setLname(lname);
        emp.setAddress(address);
        emp.setCity(city);
        emp.setZip(zip);
        emp.setPhone(phone);
        emp.setSsn(ssn);
        dbEmp.updateCustomer(emp);
        
        
    }
	public void insertNewCustomer(String fname, String lname,String address,String city,int zip,String phone,int ssn)
    {    

         try{
          DbConnection.startTransaction();
          DBCustomer dbEmp = new DBCustomer();
          dbEmp.createCustomer(fname,lname,address, city, zip, phone, ssn);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	public void deleteCustomer(int cID)
	{ DBCustomer db = new DBCustomer();
	   db.deleteCustomer(cID);
		}
	/* END OF Customer CTR*/
}

